package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import com.isunland.managesystem.entity.CustomerDialog;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/5/2 17:00
 */
public class RepeatCycleDialogFragment extends android.support.v4.app.DialogFragment {
  protected static final String EXTRA_CONTENT = "com.isunland.managesystem.ui.EXTRA_CONTENT";

  @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(getChoiceName(), 0,
        new DialogInterface.OnClickListener() {
          @Override public void onClick(DialogInterface dialog, int which) {

            String cycleCode;
            switch (which) {
              case 0:
                //每周
                cycleCode = "1";
                break;
              case 1:
                //每月
                cycleCode = "2";
                break;
              default:
                cycleCode = "";
                break;
            }

            if (getTargetFragment() == null) return;

            CustomerDialog customerDialog = new CustomerDialog(getChoiceName()[which], cycleCode);
            Intent i = new Intent();
            i.putExtra(EXTRA_CONTENT, customerDialog);
            getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, i);

            dialog.dismiss();
          }
        }).create();
  }

  private String[] getChoiceName() {

    return new String[] { "每周", "每月" };
  }
}
